package com.leetcode.August;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Description: 排序链表
 * @Author: Mr.Fxy
 * @CreateTime: 2024-07-29 20:34
 */
public class SortList {
    public ListNode sortList(ListNode head) {
        List<Integer> list = new ArrayList<>();
        ListNode current = head;
        while (current != null) {
            list.add(current.val);
            current = current.next;
        }
        Collections.sort(list);
        ListNode node = new ListNode(0);
        ListNode temp = node;
        for (Integer i : list) {
            temp.next = new ListNode( i);
            temp = temp.next;
        }
        return node.next;
    }
}
